﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNetStar.TheKing.Domain
{
    using Infrastructure;
    public class DatabaseInitializer
    {
        public static void Initialize(TheKingDbContext context)
        {
            context.Database.EnsureCreated();

            var pointStrategies = context.Set<PointsStrategy>();
            if (!pointStrategies.Any())
            {

                pointStrategies.AddRange(
                    new PointsStrategy()
                    {
                        Id = PointStrategyTypes.NewRegister.ToString(),
                        Name = PointStrategyTypes.NewRegister.GetDescription(),
                        ExpPoints = 10,
                        TradingPoints = 5
                    },
                    new PointsStrategy()
                    {
                        Id = PointStrategyTypes.PostContent.ToString(),
                        Name = PointStrategyTypes.PostContent.GetDescription(),
                        ExpPoints = 10,
                        TradingPoints = 5
                    },
                    new PointsStrategy()
                    {
                        Id = PointStrategyTypes.ReplyContent.ToString(),
                        Name = PointStrategyTypes.ReplyContent.GetDescription(),
                        ExpPoints = 3,
                        TradingPoints = 0
                    },
                     new PointsStrategy()
                     {
                         Id = PointStrategyTypes.PostCode.ToString(),
                         Name = PointStrategyTypes.PostCode.GetDescription(),
                         ExpPoints = 3,
                         TradingPoints = 1
                     },
                      new PointsStrategy()
                      {
                          Id = PointStrategyTypes.SignIn.ToString(),
                          Name = PointStrategyTypes.SignIn.GetDescription(),
                          ExpPoints = 8,
                          TradingPoints = 2
                      },
                      new PointsStrategy()
                      {
                          Id = PointStrategyTypes.DeleteCode.ToString(),
                          Name = PointStrategyTypes.DeleteCode.GetDescription(),
                          ExpPoints = -3,
                          TradingPoints = -1
                      },
                      new PointsStrategy()
                      {
                          Id = PointStrategyTypes.DeleteContent.ToString(),
                          Name = PointStrategyTypes.DeleteContent.GetDescription(),
                          ExpPoints = -10,
                          TradingPoints = -5
                      },
                      new PointsStrategy()
                      {
                          Id = PointStrategyTypes.DeleteReply.ToString(),
                          Name = PointStrategyTypes.DeleteReply.GetDescription(),
                          ExpPoints = -2,
                          TradingPoints = -1
                      },
                       new PointsStrategy()
                       {
                           Id = PointStrategyTypes.PostVideo.ToString(),
                           Name = PointStrategyTypes.PostVideo.GetDescription(),
                           ExpPoints = 6,
                           TradingPoints = 3
                       },
                       new PointsStrategy()
                       {
                           Id = PointStrategyTypes.DeleteVideo.ToString(),
                           Name = PointStrategyTypes.DeleteVideo.GetDescription(),
                           ExpPoints = -10,
                           TradingPoints = -3
                       },
                       new PointsStrategy()
                       {
                           Id = PointStrategyTypes.Like.ToString(),
                           Name = PointStrategyTypes.Like.GetDescription(),
                           ExpPoints = 0,
                           TradingPoints = 2
                       },
                       new PointsStrategy()
                       {
                           Id = PointStrategyTypes.Unlike.ToString(),
                           Name = PointStrategyTypes.Unlike.GetDescription(),
                           ExpPoints = 0,
                           TradingPoints = -2
                       }
                    );

            }

            var categories= context.Set<Category>().ToList();
            if (!categories.Any())
            {

                context.Set<Category>().AddRange(
                    new Category
                    {
                        Name = "C#语法",
                    },
                    new Category
                    {
                        Name = "桌面应用程序开发",
                    },
                    new Category
                    {
                        Name = "Web 开发",
                    }, new Category
                    {
                        Name = "服务应用开发",
                    },

                    new Category
                    {
                        Name = "框架与架构系列",
                    },

                    new Category
                    {
                        Name = "非技术类",
                    }
                    );
            }
            context.SaveChanges();
        }
    }
}
